home *** CD-ROM | disk | FTP | other *** search
- /**
- GRAB Graph Layout and Browser System
-
- Copyright (c) 1989, Tera Computer Company
- **/
-
- /**
- pred.c -- routines for reading and executing (predicate) commands
- **/
-
- #include "malloc.h"
- #include <stdio.h>
- #include <pwd.h>
- #include <strings.h>
-
- #include "attribute.h"
- #include "digraph.h"
- #include "interf.h"
- #include "pparse.h"
- #include "globals.h"
- #include "cursor.h"
-
- void DoGraph();
- void DoLayoutGraph();
- PTREE *get_commands();
- static FILE *commfile;
-
- int EndDoGetCommandsFromFile();
-
- void DoGetCommandsFromFile()
- {
- IChangeStatusLine("Type name of file with commands", FALSE);
- TakeTextInput(EndDoGetCommandsFromFile);
- }
-
- static char newName[MAXSTR]; /* new file name */
-
- #define BAD 0
- #define OK 1
-
- EndDoGetCommandsFromFile()
- {
- int status = OK;
- char *buf;
- char name[MAXSTR];
-
- OutofText(newName);
-
- if (newName[0] != '\0') /* if user entered a name */
- {
- if (newName[0] == '~')
- {
- status = expand_tilde(newName, name);
- }
-
- if (status == BAD || newName[0] != '~')
- {
- strcpy(name, newName); /* copy name of file to global var */
- }
- }
-
- buf = (char *) malloc(sizeof(char) * MAXSTR * 2);
-
- if (newName[0] == '\0')
- {
- IChangeStatusLine("No filename; no commands read", FALSE);
- }
- else if (status != OK)
- {
- sprintf(buf, "bad file name: \"%s\"", name);
- IChangeStatusLine(buf, FALSE);
- dispose(buf);
- }
- else
- {
- read_commands(name, FALSE);
- }
- }
-
- read_commands(name, layout)
- char *name;
- BOOL layout; /* layout again no matter what */
- /* read commands from the file name */
- {
- char *buf;
- BOOL relayout, newattr, changed, err, focus;
- PTREE *ptree;
- NODE *fnode;
-
- buf = (char *) malloc(sizeof(char) * MAXLINE);
- sprintf(buf, "reading commands from \"%s\"", name);
- IChangeStatusLine(buf, TRUE);
- ISetCursor(waitC);
-
- if (*name != '\0' && (commfile = fopen(name, "r")) != NULL)
- {
- init_parse(commfile);
- ptree = get_commands(&err);
-
- if (err)
- {
- IChangeStatusLine("Command parse error. Commands not executed.",
- FALSE);
-
- if (layout)
- {
- IChangeStatusLine("Laying out graph", TRUE);
- DisplayReadGraph();
- }
- }
- else
- {
- exec_commands(ptree, &err, &changed, &relayout, &newattr, &focus,
- &fnode);
- dispose_ptree(ptree);
- fclose(commfile);
-
- if (layout && !relayout)
- {
- IChangeStatusLine("Laying out graph", TRUE);
- DisplayReadGraph(); /* lays it out only if it has to */
- changed = FALSE;
- }
- else if (layout && relayout)
- {
- IChangeStatusLine("Laying out graph", TRUE);
- FixUp(); /* always lay out */
- DisplayNewGraph();
- relayout = FALSE; /* don't do it again */
- changed = FALSE;
- }
-
- if (!err)
- {
- if (changed)
- {
- ckpt_done = FALSE;
- graphChanged = TRUE;
-
- if (relayout)
- {
- IChangeStatusLine("Laying out graph", TRUE);
- relay_digraph(digraph);
- }
-
- if (newattr)
- {
- DisplayNewGraph();
- }
- else
- {
- StartDisp();
- }
- }
-
- if (focus)
- {
- if (Displayed(fnode))
- {
- FocusNode(fnode);
- }
- }
-
- if (focus && !Displayed(fnode))
- {
- IChangeStatusLine("Final focus command not executed; node is hidden", FALSE);
- }
- else
- {
- IChangeStatusLine("Commands executed.", FALSE);
- }
- }
- else
- {
- IChangeStatusLine("Command execution error. Commands not executed", FALSE);
- }
- }
- }
- else
- {
- if (layout)
- {
- IChangeStatusLine("Laying out graph", TRUE);
- DisplayReadGraph();
- }
-
-
- if (*name != '\0')
- {
- sprintf(buf, "Couldn't open %s", name);
- IChangeStatusLine(buf, FALSE);
- }
- else
- {
- IChangeStatusLine("No file to read", FALSE);
- }
- }
-
- IUnsetCursor();
- dispose(buf);
- }
-